package client;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import client.InvestComWorker_1_GUI;
import client.InvestComWorker_2_GUI;
import client.InvestComWorker_3_GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.naming.ConfigurationException;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import server.*;
import java.awt.Font;
public class InvestComPost_GUI extends JDialog {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	/*
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					InvestComPost_GUI frame = new InvestComPost_GUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public InvestComPost_GUI()throws ConfigurationException , RemoteException ,MalformedURLException,NotBoundException {
		setTitle("\u804C\u5458");
		setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u8BF7\u786E\u8BA4\u60A8\u7684\u804C\u4F4D\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 15));
		lblNewLabel.setBounds(66, 29, 181, 23);
		contentPane.add(lblNewLabel);
		
		
		final Person per=new Person();
;
		
		try
		{
			Configuration config=new Configuration();
			String rmiAddress=config.getRmiAddress();
			final PersonInterface PI=(PersonInterface) Naming.lookup(rmiAddress+"Person");
			final CompanyInterface CI=(CompanyInterface) Naming.lookup(rmiAddress+"Company");
			
			if(PI.getJob(per.getPID()).equals("普通工作人员"))
			{
			
				JButton button = new JButton("普通工作人员");
			button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				dispose();
				InvestComWorker_1_GUI dialog;
				dialog = new InvestComWorker_1_GUI();
				dialog.setLocationRelativeTo(null);
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
				
			}
		});
		button.setBounds(152, 72, 120, 23);
		contentPane.add(button);
			}
		else if(PI.getJob(per.getPID()).equals("部门经理"))
			{
		JButton btnNewButton = new JButton("\u90E8\u95E8\u7ECF\u7406");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				InvestComWorker_2_GUI dialog = new InvestComWorker_2_GUI();
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
		btnNewButton.setBounds(152, 115, 120, 23);
		contentPane.add(btnNewButton);
			}
		else if(PI.getJob(per.getPID()).equals("董事"))
		{
			{
		JButton button_1 = new JButton("\u8463\u4E8B");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
				InvestComWorker_3_GUI dialog = new InvestComWorker_3_GUI();
				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
				dialog.setVisible(true);
			}
		});
		button_1.setBounds(157, 137, 93, 23);
		contentPane.add(button_1);
			}
		
			}

		JButton button_3 = new JButton("\u8F9E\u804C");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					int pid = per.getPID();
					CI.setStaffNum(PI.getComID(pid), CI.getStaffID(pid));
					PI.apply(pid, "无");
					PI.setComID(pid, 0);
					dispose();
				} catch (RemoteException e1) {
					e1.printStackTrace();
				}
			}
		});
		button_3.setBounds(307, 208, 120, 23);
		contentPane.add(button_3);
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
	}
}
